package 匹配模式

object _操作符 {
  def main(args: Array[String]): Unit = {
    val n1 = 1
    val n2 = 2
    val r1 = n1 + n2
    val r2 = n1.+(n2)
    val monster = new Monster
    monster + 10
    println(monster.money)
    monster.++
    println(monster.money)
    !monster
    println(monster.money)

  }
}

class Monster {
  var money: Int = 0

  //对操作符进行重载
  def +(n: Int): Unit = {
    this.money += n
  }

  //操作符后置重载
  def ++(): Unit = {
    this.money += 1
  }

  //前置操作符重载
  def unary_!(): Unit = {
    this.money = -this.money
  }
}